package com.example.task1.ui.AllService.word;

import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.example.task1.R;
import com.example.task1.application.MyApplication;
import com.example.task1.bean.WordJobListBean;
import com.example.task1.http.Api;
import com.example.task1.ui.BaseAdapter;
import com.example.task1.util.ApiResp;
import com.example.task1.util.CallBack;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import retrofit2.Call;

public class WordJobListAdapter extends BaseAdapter<WordJobListBean.RowsBean> {

    private TextView tvTitle;
    private TextView tvThe;
    private TextView tvMoney;
    private TextView tvPersonName;
    private TextView tvJob;
    private TextView tvIn;
    private TextView tvNeed;
    private TextView tvAddress;
    public List<WordJobListBean.RowsBean> data = new ArrayList<>();
    private Button btnSend;

    @Override
    protected void setData(List<WordJobListBean.RowsBean> rows) {
        int size = data.size();
        data.addAll(rows);
        notifyItemInserted(size);
    }

    @Override
    protected int getLayout() {
        return R.layout.wordjoblist;
    }

    @Override
    protected Context getContext() {
        return null;
    }

    @Override
    protected List<WordJobListBean.RowsBean> getData() {
        return data;
    }

    @Override
    protected void onBind(myHolder holder, WordJobListBean.RowsBean date) {
        tvTitle.setText(date.getName());
        tvAddress.setText("地址：" + date.getAddress());
        tvIn.setText("职责：" + date.getObligation());
        tvJob.setText("岗位：" + date.getProfessionName());
        tvMoney.setText(date.getSalary() + "K");
        tvNeed.setText("要求：" + date.getNeed());
        tvPersonName.setText("负责人：" + date.getSalary());
        tvThe.setText("公司：" + date.getCompanyName());
        btnSend.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                HashMap<String, Object> map = new HashMap<>();
                map.put("companyId",date.getCompanyId());
                map.put("companyName",date.getCompanyName());
                map.put("money","3000");
                map.put("postName",date.getName());
                map.put("postId",date.getId());
//                map.put("satrTime",new Date().toString());
                map.put("userId",MyApplication.user.getUserId());
                map.put("userName",MyApplication.user.getUserName());
                Call<ApiResp> post = Api.api().post(MyApplication.TOKEN, "/prod-api/api/job/deliver", Api.getBody(map));
                Api.send(post,ApiResp.class, new CallBack<ApiResp>() {
                    @Override
                    public void success(ApiResp data) {
                        MyApplication.show("投递简历成功");
                    }

                    @Override
                    public void error(String msg) {

                    }
                });
            }
        });
    }

    @Override
    protected void holder(View itemView) {
        initView(itemView);
    }

    private void initView(View itemView) {
        tvTitle = itemView.findViewById(R.id.tv_title);
        tvThe = itemView.findViewById(R.id.tv_the);
        tvMoney = itemView.findViewById(R.id.tv_money);
        tvPersonName = itemView.findViewById(R.id.tv_personName);
        tvJob = itemView.findViewById(R.id.tv_job);
        tvIn = itemView.findViewById(R.id.tv_in);
        tvNeed = itemView.findViewById(R.id.tv_need);
        tvAddress = itemView.findViewById(R.id.tv_address);
        btnSend = (Button) itemView.findViewById(R.id.btn_send);
    }
}
